package leetcode_1201_1300;

public class LeeCode_1221 {
    public static void main(String[] args) {

    }
    private static int balancedStringSplit(String s) {
        int n = s.length(), ans = 0;
        int[][] sums = new int[n + 1][2];
        for (int i = 0; i < n; i++) {
            char c = s.charAt(i);
            sums[i + 1][0] = sums[i][0];
            sums[i + 1][1] = sums[i][1];
            if (c == 'L'){
                sums[i + 1][0]++;
            }else {
                sums[i + 1][1]++;
            }
            if (sums[i + 1][0] == sums[i + 1][1]){
                ans++;
            }
        }
        return ans;
    }
}